package com.qf.servlet;

import com.qf.entity.Book;
import com.qf.service.BookService;
import com.qf.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 孙亚梅
 * @version V1.0
 * @Project bookApp-homework
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/15 20:37
 */
@WebServlet(name = "ToUpdateServlet",urlPatterns = "/toUpdate")
public class ToUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取前端传过来的bookid
        String bookId = request.getParameter("bookId");

        BookService bookService =new BookServiceImpl();
        //获取修改图书信息
        Book book= bookService.getBook(bookId);

        //请求转发到修改页面，将获取到的数据保存到域中
        request.setAttribute("book", book);
        request.getRequestDispatcher("/updateBook.jsp").forward(request, response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
